package com.example.flashsales.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 结果集实体类
 */
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    //返回状态码
    private String code;
    //返回描述 001 成功 401 失败 404身份异常退出登录
    private String msg;
    //返回数据
    private Object data;

    public static Result ok() {
        Result result = new Result();
        result.setCode("200");
        result.setMsg("请求成功");
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.setCode("200");
        result.setMsg(msg);
        return result;
    }

    public static Result ok(Object data) {
        Result result = new Result();
        result.setCode("001");
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    public static Result ok(String msg, Object data) {
        Result result = new Result();
        result.setCode("001");
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public String getCode() {
        return code;
    }

    public Result setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public static Result error() {
        Result result = new Result();
        result.setCode("401");
        result.setMsg("请求失败");
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode("401");
        result.setMsg(msg);
        return result;
    }

}
